/*
 * ComplexChaosView.java
 */

package complexchaos;

import java.awt.Color;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;

/**
 * The application's main frame.
 * @author Dan Kotowski
 */
public class ComplexChaosView extends FrameView {

    private Double RealLowerFieldValue, ImagLowerFieldValue, RealUpperFieldValue, ImagUpperFieldValue, RealSeedFieldValue, ImagSeedFieldValue, EscapeRadiusFieldValue;
    private ExpFormula F;
    private JuliaSet julia;
    private DensityPlot density;
    private int MaxIterFieldValue, DivisionsFieldValue;

    public ComplexChaosView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = ComplexChaosApp.getApplication().getMainFrame();
            aboutBox = new ComplexChaosAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        ComplexChaosApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        SettingsFrame = new javax.swing.JInternalFrame();
        RealLowerField = new javax.swing.JTextField();
        RealUpperField = new javax.swing.JTextField();
        ImagLowerField = new javax.swing.JTextField();
        ImagUpperField = new javax.swing.JTextField();
        RealSeedField = new javax.swing.JTextField();
        ImagSeedField = new javax.swing.JTextField();
        FunctionField = new javax.swing.JTextField();
        SeedLabel2 = new javax.swing.JLabel();
        SeedLabel3 = new javax.swing.JLabel();
        FofZLabel = new javax.swing.JLabel();
        RealLabel = new javax.swing.JLabel();
        ImagLabel = new javax.swing.JLabel();
        SeedLabel1 = new javax.swing.JLabel();
        MaxIterField = new javax.swing.JTextField();
        IterLabel = new javax.swing.JLabel();
        RenderButton = new javax.swing.JButton();
        DivisionsField = new javax.swing.JTextField();
        DivisionsLabel = new javax.swing.JLabel();
        EscapeRadiusField = new javax.swing.JTextField();
        RadiusLabel = new javax.swing.JLabel();
        JuliaFrame = new javax.swing.JInternalFrame();
        JuliaGraph = new complexchaos.GraphBoard(400, 400, Color.BLACK);
        jInternalFrame1 = new javax.swing.JInternalFrame();
        DensityGraph = new complexchaos.GraphBoard(400, 400, Color.BLACK);
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(complexchaos.ComplexChaosApp.class).getContext().getResourceMap(ComplexChaosView.class);
        SettingsFrame.setTitle(resourceMap.getString("SettingsFrame.title")); // NOI18N
        SettingsFrame.setName("SettingsFrame"); // NOI18N
        SettingsFrame.setVisible(true);

        RealLowerField.setText(resourceMap.getString("RealLowerField.text")); // NOI18N
        RealLowerField.setName("RealLowerField"); // NOI18N

        RealUpperField.setText(resourceMap.getString("RealUpperField.text")); // NOI18N
        RealUpperField.setName("RealUpperField"); // NOI18N

        ImagLowerField.setText(resourceMap.getString("ImagLowerField.text")); // NOI18N
        ImagLowerField.setName("ImagLowerField"); // NOI18N

        ImagUpperField.setText(resourceMap.getString("ImagUpperField.text")); // NOI18N
        ImagUpperField.setName("ImagUpperField"); // NOI18N

        RealSeedField.setText(resourceMap.getString("RealSeedField.text")); // NOI18N
        RealSeedField.setName("RealSeedField"); // NOI18N

        ImagSeedField.setText(resourceMap.getString("ImagSeedField.text")); // NOI18N
        ImagSeedField.setName("ImagSeedField"); // NOI18N

        FunctionField.setText(resourceMap.getString("FunctionField.text")); // NOI18N
        FunctionField.setName("FunctionField"); // NOI18N

        SeedLabel2.setText(resourceMap.getString("SeedLabel2.text")); // NOI18N
        SeedLabel2.setName("SeedLabel2"); // NOI18N

        SeedLabel3.setText(resourceMap.getString("SeedLabel3.text")); // NOI18N
        SeedLabel3.setName("SeedLabel3"); // NOI18N

        FofZLabel.setText(resourceMap.getString("FofZLabel.text")); // NOI18N
        FofZLabel.setName("FofZLabel"); // NOI18N

        RealLabel.setText(resourceMap.getString("RealLabel.text")); // NOI18N
        RealLabel.setName("RealLabel"); // NOI18N

        ImagLabel.setText(resourceMap.getString("ImagLabel.text")); // NOI18N
        ImagLabel.setName("ImagLabel"); // NOI18N

        SeedLabel1.setText(resourceMap.getString("SeedLabel1.text")); // NOI18N
        SeedLabel1.setName("SeedLabel1"); // NOI18N

        MaxIterField.setText(resourceMap.getString("MaxIterField.text")); // NOI18N
        MaxIterField.setName("MaxIterField"); // NOI18N

        IterLabel.setText(resourceMap.getString("IterLabel.text")); // NOI18N
        IterLabel.setName("IterLabel"); // NOI18N

        RenderButton.setText(resourceMap.getString("RenderButton.text")); // NOI18N
        RenderButton.setName("RenderButton"); // NOI18N
        RenderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RenderButtonActionPerformed(evt);
            }
        });

        DivisionsField.setText(resourceMap.getString("DivisionsField.text")); // NOI18N
        DivisionsField.setName("DivisionsField"); // NOI18N

        DivisionsLabel.setText(resourceMap.getString("DivisionsLabel.text")); // NOI18N
        DivisionsLabel.setName("DivisionsLabel"); // NOI18N

        EscapeRadiusField.setText(resourceMap.getString("EscapeRadiusField.text")); // NOI18N
        EscapeRadiusField.setName("EscapeRadiusField"); // NOI18N

        RadiusLabel.setText(resourceMap.getString("RadiusLabel.text")); // NOI18N
        RadiusLabel.setName("RadiusLabel"); // NOI18N

        org.jdesktop.layout.GroupLayout SettingsFrameLayout = new org.jdesktop.layout.GroupLayout(SettingsFrame.getContentPane());
        SettingsFrame.getContentPane().setLayout(SettingsFrameLayout);
        SettingsFrameLayout.setHorizontalGroup(
            SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(SettingsFrameLayout.createSequentialGroup()
                .addContainerGap()
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(FofZLabel)
                    .add(RealLabel)
                    .add(ImagLabel)
                    .add(SeedLabel1)
                    .add(IterLabel)
                    .add(DivisionsLabel)
                    .add(RadiusLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(SettingsFrameLayout.createSequentialGroup()
                        .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, FunctionField)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, SettingsFrameLayout.createSequentialGroup()
                                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(ImagLowerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(RealLowerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(RealSeedField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(SeedLabel2)
                                .add(6, 6, 6)
                                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(RealUpperField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, ImagUpperField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(org.jdesktop.layout.GroupLayout.TRAILING, ImagSeedField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(SeedLabel3))
                    .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, EscapeRadiusField)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, DivisionsField)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, MaxIterField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                        .add(RenderButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        SettingsFrameLayout.setVerticalGroup(
            SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(SettingsFrameLayout.createSequentialGroup()
                .addContainerGap()
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(FunctionField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(FofZLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(RealLowerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(RealUpperField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(RealLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(ImagLowerField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ImagUpperField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(ImagLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(RealSeedField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(SeedLabel2)
                    .add(ImagSeedField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(SeedLabel3)
                    .add(SeedLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(MaxIterField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(IterLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(DivisionsField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(DivisionsLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(SettingsFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(EscapeRadiusField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(RadiusLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(RenderButton)
                .addContainerGap(130, Short.MAX_VALUE))
        );

        JuliaFrame.setTitle(resourceMap.getString("JuliaFrame.title")); // NOI18N
        JuliaFrame.setName("JuliaFrame"); // NOI18N
        JuliaFrame.setVisible(true);

        JuliaGraph.setName("JuliaGraph"); // NOI18N

        org.jdesktop.layout.GroupLayout JuliaGraphLayout = new org.jdesktop.layout.GroupLayout(JuliaGraph);
        JuliaGraph.setLayout(JuliaGraphLayout);
        JuliaGraphLayout.setHorizontalGroup(
            JuliaGraphLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        JuliaGraphLayout.setVerticalGroup(
            JuliaGraphLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout JuliaFrameLayout = new org.jdesktop.layout.GroupLayout(JuliaFrame.getContentPane());
        JuliaFrame.getContentPane().setLayout(JuliaFrameLayout);
        JuliaFrameLayout.setHorizontalGroup(
            JuliaFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(JuliaGraph, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        JuliaFrameLayout.setVerticalGroup(
            JuliaFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(JuliaGraph, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        jInternalFrame1.setTitle(resourceMap.getString("jInternalFrame1.title")); // NOI18N
        jInternalFrame1.setName("jInternalFrame1"); // NOI18N
        jInternalFrame1.setVisible(true);

        DensityGraph.setName("DensityGraph"); // NOI18N

        org.jdesktop.layout.GroupLayout DensityGraphLayout = new org.jdesktop.layout.GroupLayout(DensityGraph);
        DensityGraph.setLayout(DensityGraphLayout);
        DensityGraphLayout.setHorizontalGroup(
            DensityGraphLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );
        DensityGraphLayout.setVerticalGroup(
            DensityGraphLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 400, Short.MAX_VALUE)
        );

        org.jdesktop.layout.GroupLayout jInternalFrame1Layout = new org.jdesktop.layout.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(DensityGraph, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(DensityGraph, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(SettingsFrame, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 380, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(JuliaFrame, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 416, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jInternalFrame1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 416, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(824, 824, 824))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jInternalFrame1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, JuliaFrame, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 431, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, SettingsFrame, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(1070, 1070, 1070))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(complexchaos.ComplexChaosApp.class).getContext().getActionMap(ComplexChaosView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 2062, Short.MAX_VALUE)
            .add(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(statusMessageLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 1892, Short.MAX_VALUE)
                .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(statusPanelLayout.createSequentialGroup()
                .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(statusMessageLabel)
                    .add(statusAnimationLabel)
                    .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void RenderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RenderButtonActionPerformed
        // TODO add your handling code here:
        try {
            RealLowerFieldValue = Double.parseDouble(RealLowerField.getText());
        }
        catch (NumberFormatException e) {
            RealLowerFieldValue = -2.5;
        }
        try {
            ImagLowerFieldValue = Double.parseDouble(ImagLowerField.getText());
        }
        catch (NumberFormatException e) {
            ImagLowerFieldValue = -2.5;
        }
        try {
            RealUpperFieldValue = Double.parseDouble(RealUpperField.getText());
        }
        catch (NumberFormatException e) {
            RealUpperFieldValue = 2.5;
        }
        try {
            ImagUpperFieldValue = Double.parseDouble(ImagUpperField.getText());
        }
        catch (NumberFormatException e) {
            ImagUpperFieldValue = 2.5;
        }
        try {
            RealSeedFieldValue = Double.parseDouble(RealSeedField.getText());
        }
        catch (NumberFormatException e) {
            RealSeedFieldValue = 0.0;
        }
        try {
            ImagSeedFieldValue = Double.parseDouble(ImagSeedField.getText());
        }
        catch (NumberFormatException e) {
            ImagSeedFieldValue = 0.0;
        }
        try {
            MaxIterFieldValue = Integer.parseInt(MaxIterField.getText());
        }
        catch (NumberFormatException e) {
            MaxIterFieldValue = 100;
        }
        try {
            DivisionsFieldValue = Integer.parseInt(DivisionsField.getText());
        }
        catch (NumberFormatException e) {
            DivisionsFieldValue = 50;
        }
        try {
            EscapeRadiusFieldValue = Double.parseDouble(EscapeRadiusField.getText());
        }
        catch (NumberFormatException e) {
            EscapeRadiusFieldValue = 4.0;
        }

        ComplexNumber lowerBound = new ComplexNumber( (double) RealLowerFieldValue, (double) ImagLowerFieldValue );
        ComplexNumber upperBound = new ComplexNumber( (double) RealUpperFieldValue, (double) ImagUpperFieldValue );
        ComplexNumber seed = new ComplexNumber( (double) RealSeedFieldValue, (double) ImagSeedFieldValue);
        // Need to fix this so that the render box size is adjustable
        F = new ExpFormula(FunctionField.getText());
        //julia = new JuliaSet(lowerBound, upperBound, F, MaxIterFieldValue, EscapeRadiusFieldValue, 400, 400 );
        density = new DensityPlot(lowerBound, upperBound, F, MaxIterFieldValue, seed, (int) DivisionsFieldValue );
        //julia.computeFilledJuliaSet();
        // ArrayList filledSet = new ArrayList(julia.getFilledSet());
        int[][] count = density.getDensityPlot();
        double scale = 255.0/density.getMax();
        // Draw graphs
        for (int i = 0; i < 400; ++i) {
            for (int j = 0; j < 400; ++j) {
                ComplexNumber z = new ComplexNumber((i / 80.0) - lowerBound.getReal().approx(), (j / 80.0) - lowerBound.getImag().approx());
                //if (julia.inSet(z))
                    //JuliaGraph.setRGB((int) i, (int) j, 0xFFFFFFFF);
                int index1 = i*(DivisionsFieldValue-1)/DensityGraph.getWidth();
                int index2 = j*(DivisionsFieldValue-1)/DensityGraph.getHeight();
                int brightness = (int)(scale*count[index1][index2]);
                Color c = new Color(brightness, brightness, brightness);
                DensityGraph.setRGBColor(i, j, c);
            }
        }
        DensityGraph.repaint();
    }//GEN-LAST:event_RenderButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private complexchaos.GraphBoard DensityGraph;
    private javax.swing.JTextField DivisionsField;
    private javax.swing.JLabel DivisionsLabel;
    private javax.swing.JTextField EscapeRadiusField;
    private javax.swing.JLabel FofZLabel;
    private javax.swing.JTextField FunctionField;
    private javax.swing.JLabel ImagLabel;
    private javax.swing.JTextField ImagLowerField;
    private javax.swing.JTextField ImagSeedField;
    private javax.swing.JTextField ImagUpperField;
    private javax.swing.JLabel IterLabel;
    private javax.swing.JInternalFrame JuliaFrame;
    private complexchaos.GraphBoard JuliaGraph;
    private javax.swing.JTextField MaxIterField;
    private javax.swing.JLabel RadiusLabel;
    private javax.swing.JLabel RealLabel;
    private javax.swing.JTextField RealLowerField;
    private javax.swing.JTextField RealSeedField;
    private javax.swing.JTextField RealUpperField;
    private javax.swing.JButton RenderButton;
    private javax.swing.JLabel SeedLabel1;
    private javax.swing.JLabel SeedLabel2;
    private javax.swing.JLabel SeedLabel3;
    private javax.swing.JInternalFrame SettingsFrame;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
